<script setup lang="ts">
import { onMounted } from 'vue'
import { ElCard, ElInput, ElLink } from 'element-plus'
import useLists from './useLists'
import BScrollbar from '@/components/b-scrollbar/index.vue'

const { lists, queryLists, clickSave } = useLists()

onMounted(() => {
  queryLists()
})
</script>

<template>
  <div class="container">
    <BScrollbar>
      <div class="grid">
        <div v-for="item of lists" :key="item.id" class="grid-item">
          <ElCard class="item-card" body-style="flex: 1;">
            <template #header>
              <div class="card-head">
                <strong>{{ item.name }}</strong>
                <ElLink class="margin-left-auto" type="primary" :underline="false" @click="clickSave">
                  保存
                </ElLink>
              </div>
            </template>
            <ElInput v-model="item.description" type="textarea" resize="none" :autosize="false" />
          </ElCard>
        </div>
      </div>
    </BScrollbar>
  </div>
</template>

<style scoped>
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 324px);
  gap: 1rem;
}
.card-head {
  border-left: 4px solid var(--el-color-primary);
  padding-left: 10px;
  display: flex;
  align-items: center;
}
.item-card {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.item-card :deep(.el-textarea),
.item-card :deep(.el-textarea__inner) {
  height: 100%;
}
</style>
